// copyright jyz.2024

#pragma once

#include "CoreMinimal.h"
#include "UI/WidgetController/AuraWidgetController.h"
#include "OverlayWidgetController.generated.h"

class UAuraUserWidget;
USTRUCT(BlueprintType)
struct FUIWidgetRow:public FTableRowBase
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere,BlueprintReadOnly)
	FGameplayTag MessageTags = FGameplayTag();
	UPROPERTY(EditAnywhere,BlueprintReadOnly)
	FText Message = FText();
	UPROPERTY(EditAnywhere,BlueprintReadOnly)
	TSubclassOf<UAuraUserWidget> MessageWidget;
	UPROPERTY(EditAnywhere,BlueprintReadOnly)
	UTexture2D* MessageIcon=nullptr;
};

DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnAttributeChangeSignature, float, NewValue);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnMessageWidgetSignature, FUIWidgetRow, UIWidgetRow);


UCLASS(Blueprintable,BlueprintType)
class AURARPGDEMO_API UOverlayWidgetController : public UAuraWidgetController
{
	GENERATED_BODY()
public:

	virtual void BroadcastInitialValues()override;
	UPROPERTY(BlueprintAssignable,Category="GAS|Attributes")
	FOnAttributeChangeSignature OnHealthChange;
	UPROPERTY(BlueprintAssignable,Category="GAS|Attributes")
	FOnAttributeChangeSignature OnMaxHealthChange;
	UPROPERTY(BlueprintAssignable,Category="GAS|Attributes")
	FOnAttributeChangeSignature OnManaChange;
	UPROPERTY(BlueprintAssignable,Category="GAS|Attributes")
	FOnAttributeChangeSignature OnMaxManaChange;

	UPROPERTY(BlueprintAssignable,Category="GAS|Messages")
	FOnMessageWidgetSignature OnMessageWidget;

protected:
	UPROPERTY(EditDefaultsOnly,BlueprintReadOnly,Category="Widget Data")
	TObjectPtr<UDataTable> MessageWidgetDataTable;
	
	void OnEffectAssetTags(const FGameplayTagContainer& InAssetTags);

	template<typename T>
	static T* GetDataTableRowByTag(UDataTable* InDataTable,const FGameplayTag& InTag)
	{
		return InDataTable->FindRow<T>(InTag.GetTagName(),TEXT(""));
	}
};
